/* 
 * Common javascript
 * @author: lethanhquang910@gmail.com
 */

$(document).ready(function(){

    /**
     * Get top new product
     */
    get_top_new_product('top-new-product');

    /**
     * Click add to cart
     */
    $('.cart-add').live('click', function(){
        //Get productId
        var pid = $(this).attr('id');

        //Call function add to cart
        add_to_cart(pid);

        //Change text
        $(this).text('Hủy đặt hàng');

        //Change class
        $(this).attr('class', 'cart-remove red');
        
        //return data
        return false;
    });

    /**
     * Click remove from cart
     */
    $('.cart-remove').live('click', function(){
        //Get productId
        var pid = $(this).id;

        //Call function add to cart
        remove_from_cart(pid);

        //Change text
        $(this).text('Đặt hàng');

        //Change class
        $(this).attr('class', 'cart-add');

        //return data
        return false;
    });

});
